﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ComponentSample
{
    public partial class AnswerForm : Form
    {
        public AnswerForm()
        {
            InitializeComponent();
        }

        private void findAnswer_Click(object sender, EventArgs e)
        {
            answerComponent.GetAnswerAsync("What is the Answer to the Ultimate Question of Life, the Universe and Everything");
        }
  
        private void cancel_Click(object sender, EventArgs e)
        {
            answerComponent.CancelAsync();
        }

        private void answerComponent_GetAnswerCompleted(object sender, AsyncFuncCompletedEventArgs<string> e)
        {
            if (e.Error != null)
            {
                // Report exception
            }
            else if (e.Cancelled)
            {
                // Ignore
                MessageBox.Show("Operation cancelled");
            }
            else
            {
                textBox1.Text = e.Result;
            }
            progressBar1.Value = 0;
        }

        private void answerComponent_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;
        }

    }
}
